#!/usr/bin/env bash

[ -f ~/.ssh/id_rsa ] || ssh-keygen -f /root/.ssh/id_rsa -P ''
ssh-copy-id -o StrictHostKeyChecking=no $NEW_NODE_IP

ssh root@$NEW_NODE_IP mkdir -p /opt/kubernetes/{bin,cfg,ssl,logs}

scp -r /opt/kubernetes/bin/{kubelet,kube-proxy} $NEW_NODE_IP:/opt/kubernetes/bin/
scp -r /opt/kubernetes/ssl/ca.pem $NEW_NODE_IP:/opt/kubernetes/ssl/
scp -r /opt/kubernetes/cfg/{kubelet.conf,kubelet-config.yml,kube-proxy.conf,kube-proxy-config.yml,kube-proxy.kubeconfig,bootstrap.kubeconfig} $NEW_NODE_IP:/opt/kubernetes/cfg/
scp -r /usr/lib/systemd/system/{kubelet,kube-proxy}.service $NEW_NODE_IP:/usr/lib/systemd/system/

ssh root@$NEW_NODE_IP sed -i "s/$KUBELET_CURRENT_HOSTNAME/$KUBELET_NEW_NODE_HOSTNAME/g" /opt/kubernetes/cfg/kubelet.conf
ssh root@$NEW_NODE_IP sed -i "s/$KUBELET_CURRENT_HOSTNAME/$KUBELET_NEW_NODE_HOSTNAME/g" /opt/kubernetes/cfg/kube-proxy-config.yml

## 启动服务
ssh root@$NEW_NODE_IP systemctl daemon-reload
ssh root@$NEW_NODE_IP systemctl start kubelet kube-proxy && systemctl enable kubelet kube-proxy


echo "----------- kubelet and kube-proxy status----------"
systemctl status kubelet kube-proxy






